package com.ruoyi.newSystem.mapper;


import com.ruoyi.common.core.domain.BaseEntity;
import com.ruoyi.common.core.domain.permission.vo.role.RoleExportReqVO;
import com.ruoyi.common.utils.BaseMapperX;
import com.ruoyi.common.utils.LambdaQueryWrapperX;
import com.ruoyi.common.core.domain.entity.RoleDO;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.lang.Nullable;

import java.util.Collection;
import java.util.List;

/**
 * The interface Role mapper.
 */
@Mapper
public interface RoleMapper extends BaseMapperX<RoleDO> {



    /**
     * Select list list.
     *
     * @param reqVO the req vo
     * @return the list
     */
    default List<RoleDO> selectList(RoleExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<RoleDO>()
                .likeIfPresent(RoleDO::getName, reqVO.getName())
                .likeIfPresent(RoleDO::getCode, reqVO.getCode())
                .eqIfPresent(RoleDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(BaseEntity::getCreateTime, reqVO.getCreateTime()));
    }

    /**
     * Select by name role do.
     *
     * @param name the name
     * @return the role do
     */
    default RoleDO selectByName(String name) {
        return selectOne(RoleDO::getName, name);
    }

    /**
     * Select by code role do.
     *
     * @param code the code
     * @return the role do
     */
    default RoleDO selectByCode(String code) {
        return selectOne(RoleDO::getCode, code);
    }

    /**
     * Select list by status list.
     *
     * @param statuses the statuses
     * @return the list
     */
    default List<RoleDO> selectListByStatus(@Nullable Collection<Integer> statuses) {
        return selectList(RoleDO::getStatus, statuses);
    }


    List<RoleDO> getRolesByUserId(Long userId);
}
